/*
 * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import 'package:flutter/material.dart';

typedef ButtonBuilder = Widget Function(FocusNode focusNode);

///Class to define the `focusNode` that you pass to your `TextField` too and other params to customize
///the bar that will appear over your keyboard
class KeyboardActionsItem {
  /// The Focus object coupled to TextField, listening for got/lost focus events
  final FocusNode focusNode;

  /// Optional widgets to display to the right of the bar/
  /// NOTE: `toolbarButtons` override the Done button by default
  final List<ButtonBuilder>? toolbarButtons;

  /// true [default] to display the Done button
  final bool displayDoneButton;

  /// Optional callback if the Done button for TextField was tapped
  /// It will only work if `displayDoneButton` is [true] and `toolbarButtons` is null or empty
  final VoidCallback? onTapAction;

  /// true [default] to display the arrows to move between the fields
  final bool displayArrows;

  /// true [default] if the TextField is enabled
  final bool enabled;

  /// true [default] to display the action bar
  final bool displayActionBar;

  /// Builder for an optional widget to show below the action bar.
  ///
  /// Consider using for field validation or as a replacement for a system keyboard.
  ///
  /// This widget must be a PreferredSizeWidget to report its exact height; use [Size.fromHeight]
  final PreferredSizeWidget Function(BuildContext context)? footerBuilder;

  /// Alignment of the row that displays [toolbarButtons]. If you want to show your
  /// buttons from the left side of the toolbar, you can set [toolbarAlignment] and
  /// set the value of [displayArrows] to `false`
  final MainAxisAlignment toolbarAlignment;

  const KeyboardActionsItem({
    required this.focusNode,
    this.onTapAction,
    this.toolbarButtons,
    this.enabled = true,
    this.displayActionBar = true,
    this.displayArrows = true,
    this.displayDoneButton = true,
    this.footerBuilder,
    this.toolbarAlignment = MainAxisAlignment.end,
  });
}
